﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace Strongshell.Recoil.Core.Composition.Parsing.DependencyInjection
{
    public class DictionaryDependencyInjector : NestingDependencyInjectorBase
    {
        private readonly IDictionary dictionary;
        private object dictKey;

        public DictionaryDependencyInjector(IObjectConfigurationRegistry objectConfigurationRegistry, ObjectConfiguration currentContainer, Type expectedType, IDictionary dictionary)
            : base(objectConfigurationRegistry, currentContainer, expectedType)
        {
            this.dictionary = dictionary;
        }

        public override void Inject(object value)
        {
            if (dictKey == null)
            {
                dictKey = value;
            }
            else
            {
                dictionary.Add(dictKey, value);
                dictKey = null;
            }
        }
    }
}